﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;

namespace ETRoboConResultEditorExcel
{
    public partial class Sheet9
    {
        private const int POS_EntryRow = 2;
        private const int POS_BibCol = 1;
        private const int POS_TeamNameCol = 2;
        private Dictionary<string, int> POS_InBonusCols = new Dictionary<string, int>();
        private Dictionary<string, int> POS_OutBonusCols = new Dictionary<string, int>();
        private const int POS_InCourseRT = 7;
        private const int POS_OutCourseRT = 13;

        private void Sheet9_Startup(object sender, System.EventArgs e)
        {
#if false
            POS_InBonusCols.Add("MC",5);
            POS_InBonusCols.Add("GI", 6);
            POS_OutBonusCols.Add("SST", 9);
            POS_OutBonusCols.Add("SSS", 10);
            POS_OutBonusCols.Add("ST", 11);
            POS_OutBonusCols.Add("GI", 12);
#endif
            POS_InBonusCols.Add("RS", 9);
            POS_InBonusCols.Add("ST", 16);
            POS_InBonusCols.Add("SS", 14);
            POS_InBonusCols.Add("SD", 15);
            POS_InBonusCols.Add("GII", 17);

            POS_OutBonusCols.Add("RS", 9);
            POS_OutBonusCols.Add("LUG", 10);
            POS_OutBonusCols.Add("DTI", 11);
            POS_OutBonusCols.Add("DTO", 12);
            POS_OutBonusCols.Add("GIO", 13);
        }

        private void Sheet9_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(Sheet9_Startup);
            this.Shutdown += new System.EventHandler(Sheet9_Shutdown);
        }

        #endregion

        public void WriteTeamResult(int rowIndex, int bib, string name, string course, int runTime, string[] bonusClears)
        {
            ((Excel.Range)Cells[POS_EntryRow + rowIndex, POS_BibCol]).Value2 = bib;
            ((Excel.Range)Cells[POS_EntryRow + rowIndex, POS_TeamNameCol]).Value2 = name;
            ((Excel.Range)Cells[POS_EntryRow + rowIndex, POS_BibCol]).Value2 = bib;
            if (course.CompareTo("IN") == 0)
            {
                ((Excel.Range)Cells[POS_EntryRow + rowIndex, POS_InCourseRT]).Value2 = runTime;
                foreach (var bonus in bonusClears)
                {
                    ((Excel.Range)Cells[POS_EntryRow + rowIndex, POS_InBonusCols[bonus]]).Value2 = "OK";
                }
            }
            else
            {
                ((Excel.Range)Cells[POS_EntryRow + rowIndex, POS_OutCourseRT]).Value2 = runTime;
                foreach (var bonus in bonusClears)
                {
                    ((Excel.Range)Cells[POS_EntryRow + rowIndex, POS_OutBonusCols[bonus]]).Value2 = "OK";
                }
            }
        }
    }
}
